package cn.sczc.jh.client.service;

import javax.jms.Destination;

import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

@Service
public class MQService {
	@Autowired
	private JmsMessagingTemplate jmsTemplate;

	/**
	 * 发送消息
	 * 
	 * @param destination
	 * @param message
	 */
	public void sendMessage(Destination destination, final Object message) {
		jmsTemplate.convertAndSend(destination, message);
	}

	/**
	 * 打开设备
	 * 
	 * @param deviceId
	 * @param message
	 */
	public void sendDeviceOpenMessage(String deviceId, final Object message) {
		Destination sensorDestination = new ActiveMQTopic("jh.device." + deviceId + ".command.open");
		this.sendMessage(sensorDestination, message);
	}

	/**
	 * 关闭设备
	 * 
	 * @param deviceId
	 */
	public void sendDeviceCloseMessage(String deviceId, final Object message) {
		Destination sensorDestination = new ActiveMQTopic("jh.device." + deviceId + ".command.close");
		this.sendMessage(sensorDestination, message);
	}
	
	public void sendGetDevicePortMessage(String deviceId, final Object message) {
		Destination sensorDestination = new ActiveMQTopic("jh.device." + deviceId + ".command.port");
		this.sendMessage(sensorDestination, message);
	}
	
	/**
	 * 开启云端推送
	 * @param deviceId
	 * @param message
	 */
	public void sendOpenCloudPushMessage(String deviceId, final Object message) {
		Destination sensorDestination = new ActiveMQTopic("jh.device." + deviceId + ".command.cloudpush-open");
		this.sendMessage(sensorDestination, message);
	}
	/**
	 * 关闭云端推送
	 * @param deviceId
	 * @param message
	 */
	public void sendCloseCloudPushMessage(String deviceId, final Object message) {
		Destination sensorDestination = new ActiveMQTopic("jh.device." + deviceId + ".command.cloudpush-close");
		this.sendMessage(sensorDestination, message);
	}

	/**
	 * 获取云端推送状态
	 * @param deviceId
	 * @param message
	 */
	public void sendGetCloudPushMessage(String deviceId, final Object message) {
		Destination sensorDestination = new ActiveMQTopic("jh.device." + deviceId + ".command.cloudpush");
		this.sendMessage(sensorDestination, message);
	}
}
